<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta content="telephone=no" name="format-detection" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<title>金穗服务</title>
<link type="text/css" rel="stylesheet" href="../../resource/fapiao.css">
<link rel="stylesheet" href="../../resource/weui.min.css" />
<link rel="stylesheet" href="../../resource/example.css" />
<script type="text/javascript" src="../../resource/jweixin-1_002.js"></script>
<script type="text/javascript" src="../../resource/jweixin-1.js"></script>
<script src="../../resource/jquery-1.js"></script>
<script src="../../resource/qrcode.js"></script>
<script src="../../resource/jquery-barcode.js"></script>

<script src="../../script/api.js"></script>
<script src="../../script/md5.js"></script>
<script src="../../script/ours.js"></script>
<link rel="stylesheet" href="../../resource/jinsuistyle.css" />

<script type="text/javascript">
	var token = '';
    window.apiready = function(){
      var header = $api.byId('jsheader');
      if(api.systemType=='ios'){
        $api.fixIos7Bar(header);
      }
//    else{
//      $api.fixStatusBar(header);
//    }
    }

    function xyyzf(){
     api.openWin({
		    name: 'kpmain',
		    url: './main.html',
		    pageParam: {

		    }
		});

    }

    function openYST(token){
//  	var token = getToken();
   		var op = $api.getStorage("openid");
    	if(token == '-1' || token == 'undefined'){
    		return;
    	}
    	console.info('接收第一步的值：' + token);
    	var seq = randomString(12);
    	var timeStamp = new Date().getTime();
    	var tempSign = "thirdId=" + op + "&buId=ef73d9dc381d412f964b99e521c270a6&seq=" + seq + "&timeStamp=" + timeStamp+ "&token=" + token;
		console.info('第二部签名字符串：'+ tempSign);
		tempSign = hex_md5(tempSign).toUpperCase();
		console.info('第二部签名后的字符串：'+ tempSign);
    	console.info('第二部请求地址：http://www.uphsh.com/wap/ef73d9dc381d412f964b99e521c270a6/invoice?userToken='+ op + '&timeStamp='+timeStamp+'&seq='+seq+'&sign='+tempSign);
    	// http://www.uphsh.com/wap/0d29a3eae4604c7ebdef5b3a7c037715/invoice
    	var aa = api.connectionType;
		if(aa=='none'||aa=='unknow'||aa=='ethernet'){
			api.alert({msg:'当前网络太差，请稍候再试...'});
			return ;
		}
		if(api.systemType=='ios'){
    	var browser = api.require('webBrowser');
    	var op = $api.getStorage("openid");
		browser.open({
		    url: 'http://www.uphsh.com/wap/ef73d9dc381d412f964b99e521c270a6/invoice?userToken='+ op + '&timeStamp='+timeStamp+'&seq='+seq+'&sign='+tempSign
		});
		browser.historyBack(
		    function(ret, err) {
		            browser.closeView();
		    });
		}else{
		var aa = api.connectionType;
		if(aa=='none'||aa=='unknow'||aa=='ethernet'){
			api.alert({msg:'当前网络太差，请稍候再试...'});
			return ;
		}
		console.info('http://www.uphsh.com/wap/ef73d9dc381d412f964b99e521c270a6/invoice?userToken='+ op + '&timeStamp='+timeStamp+'&seq='+seq+'&sign='+tempSign);
//		api.sendEvent({
//	        name:'openYST',
//	        extra:{
//	        	url: 'http://www.uphsh.com/wap/ef73d9dc381d412f964b99e521c270a6/invoice?userToken='+ api.deviceId + '&timeStamp='+timeStamp+'&seq='+seq+'&sign='+tempSign
//	        }
//      });
		api.openWin({
	        name: 'yst',
	        url: 'http://www.uphsh.com/wap/ef73d9dc381d412f964b99e521c270a6/invoice?userToken='+ op + '&timeStamp='+timeStamp+'&seq='+seq+'&sign='+tempSign
        });
        }
    }

    function getToken(){
    	var seq = randomString(12);
    	var timeStamp = new Date().getTime();
    	var tempStr = "buId=ef73d9dc381d412f964b99e521c270a6&seq=" + seq + "&timeStamp=" + timeStamp + "&key=2a0n1j6c0y6p0c1s";
    	console.info('第一步签名字符串:' + tempStr);
    	var  tempSign = hex_md5(tempStr).toUpperCase();
    	console.info('第一步签名后的值:' + tempSign);
    	console.info('第一步请求地址：http://www.uphsh.com/thirduser/applyToken?seq='+ seq + '&sign='+ tempSign + '&timeStamp='+timeStamp + '&number=ef73d9dc381d412f964b99e521c270a6');
    	api.ajax({
			url: 'http://www.uphsh.com/thirduser/applyToken?seq='+ seq + '&sign='+ tempSign + '&timeStamp='+timeStamp + '&number=ef73d9dc381d412f964b99e521c270a6',
			method: 'post'
//			,
//			data: {
//			    values: {
//			        openid : deviceId,
//					deviceid : userid,
//					deviceName :　deviceName
//			    }
//		 	}
		}, function(ret, err) {
		 console.info('返回值:' + JSON.stringify(ret));	
		 if (ret) {
		 	console.info('返回值:' + ret.result);
		 	openYST(ret.result);
//		 	api.ajax({
//			url: 'http://www.uphsh.com/thirduser/applyToken',
//			method: 'post'
//			}, function(ret, err) {
//			 if (ret) {
//
//			});
    }else{
    	//alert("请求异常，请稍候再试！");
    	api.alert({msg:'网络异常'});
    	return;
    }





//			 if(ret.code == 0){
//			  } else {
//			     console.log('服务请求错误,请联系管理员');
//			  }
		});
    }

</script>
<style>
.nav{
	padding: 10px 2%;
}
.bg {
    padding: 15px 0 15px;
}
.weui-grid{width:50%;}
.weui-grid__icon{width: 50px;height: 50px;}
</style>
</head>
<body>
  <div id="jsheader">
      <nav id="jsnav">
          <a id="jsleft" tapmode="" onclick="api.closeWin();">
              <span>主页</span>
          </a>
          <div id="jsmiddle">
              <strong id="jstitle">金穗服务</strong>
          </div>
          <a id="jsright">
            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
          </a>
      </nav>
  </div>
	<!-- <ul>
		<li class="hiSlider-item"><img id="banner1" src="../../resource/images/bn_zzrz1.png" style="width: 100%;"></li>
	</ul> -->
	<div class="paddingtop70" style="background-color:#fff">
		<div class="weui-grids">
			<a class="weui-grid" onclick="getToken()">
				<div class="weui-grid__icon">
					<img src="../../resource/images/coupon_icon1.png" alt="">
				</div>
				<p class="weui-grid__label">银穗通</p>
			</a>
			<a class="weui-grid" href="" onclick="xyyzf();">
				<div class="weui-grid__icon">
					<img src="../../resource/images/coupon_icon7.png" alt="">
				</div>
				<p class="weui-grid__label">兴业云支付</p>
			</a>
		</div>
	</div>
		<div class="shade" style="display: none;">
			<div style="border: 0 solid #A75A5A;width:320px;height:400px;border-radius:5px;left: 50%;top:45%;background-color: #fff;margin: -220px auto 0px -160px;position:fixed;">
				<div style="width:100%;padding-top:10px" align="right">
					<i class="weui-icon-cancel shade_div" style="font-weight:bold;color:#333;background-color:#fff;margin: 0 10px 10px;"></i>
				</div>
				<div id="bcTarget" class="barcodeImg" style="text-align:center;"></div>
				<div id="invoiceName" style="text-align: center;width: 100%;margin: 30px auto 30px auto;white-space:normal;"></div>
			</div>
		</div>
		<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
		<div class="page__ft">
				<p style="margin-bottom: 6px" ><a style="color:#777;font-size:12px">四川航天金穗高技术有限公司</a><b id="bbb"></b></p>
				</div>


</body>
</html>
